<template>
    <view>
		<!--返回-->
		<view class="back-btn" @click="jumpBtn">
		    <image src="@/static/images/new/back.png" mode="widthFix"></image>
		</view>
		<view class="container page-view" v-if="detailObj.classType == 1" >
		    <image class="image-self" mode="aspectFill" style="height: 100vh;width: 100vw;display: flex;" :src="detailObj.image"></image>
		</view>
		<view class="container page-view" v-if="detailObj.classType == 2" >
		    <video class="image-self" mode="aspectFill"  style="height: 100vh;width: 100vw;display: flex;" :src="detailObj.image" :autoplay="true"></video>
		</view>
		<view class="container page-view" v-if="detailObj.classType == 3" >
		    <image class="background-image" mode="aspectFill"  :src="detailObj.image"></image>
		</view>
		<view class="container page-view" v-if="detailObj.classType == 4" >
		    <image class="emoticon" mode="aspectFill"   :src="detailObj.image"></image>
		</view>
		<view class="container page-view" v-if="detailObj.classType == 5" >
		    <image class="emoticon" mode="aspectFill"  :src="detailObj.image"></image>
		</view>
		
		<view class="padding flex flex-wrap justify-between align-center box guoshao-delete">
			<button class="cu-btn round guoshao-bianji" @click="deleteData">删除</button>
			<button class="cu-btn round guoshao-top" @click="topping" data-topping="1" v-if="isTop == 0">置顶</button>
			<button class="cu-btn round guoshao-top" @click="topping" data-topping="0" v-if="isTop == 1">取消置顶</button>
		</view>
	</view>
</template>

<script>

/*
* Author: 郭少
* github: https://github.com/guoshao99/wallpaper-applet
* gitee: https://gitee.com/guoshao99/wallpaper-applet
* QQ：2549789059
* 微信：2549789059
*/

const Authentication = require('../../../utils/authentication.js');

const Constants = require('../../../utils/constants');

const http = require('../../../utils/http.js');


export default {
	components: {

	},
	data() {
		return {
			id:0,
			detailObj:null,
			isTop: 0,
			toppingVal:0,
			select:0, //上一页选择的
			classId:0,
			pageRefresh:1,
			topStatus: 0 //记录第一次进来的状态,用户返回做判断
		};
	},
	onLoad: function(options) {
	  this.id = options.id;
	  this.select = options.select;
	  this.classId = options.classId;
	},
	onShow: function () {
		this.getDataDetail();
	},
	onHide() {
	
	},
	onReachBottom: function () {
	
	},

	methods: {
		getDataDetail:function(){
			let that = this;
			var params = {
			  url: "/platform/getDataDetail",
			  method: "GET",
			  data: {
			    'id': that.id
			  },
			  callBack: function (res) {
			    that.setData({
			      detailObj: res.data.bzWallpaper,
				  isTop : res.data.bzWallpaper.topping,
				  topStatus:res.data.bzWallpaper.topping
			    }); 
			  }
			};
			http.request(params); 
		},
		deleteData:function(){
			let that = this;
			uni.showModal({
				title: '提示',
				content: '确定删除吗?',
				cancelText: "取消", // 取消按钮的文字  
				confirmText: "删除", // 确认按钮文字  
				showCancel: true, // 是否显示取消按钮，默认为 true
				success: (res) => {
					if(res.confirm) {  
						that.deleteImage();
					} 
				} 
			})
		},
		
		deleteImage:function(){
			let that = this;
			var params = {
			  url: "/platform/deleteImage/"+that.id,
			  method: "GET",
			  data: {
			  },
			  callBack: function (res) {
			    if(res.code == 200){
					uni.showToast({
						title:'删除成功',
						success: (res) => {
							that.pageRefresh = 1; //设置不执行代码
							setTimeout(function(){
								let pages = getCurrentPages(); // 获取所有页面栈实例列表
								let beforePage = pages[pages.length - 2]; // 上一页
								beforePage.$vm.loadPostLast(true);
								 uni.navigateBack({
								     success: function() {
								     }
								 });
							},1000);
						} 
					})
				}
			  }
			};
			http.request(params); 
		},
		topping:function(e){
			let that = this;
			let content = '确定置顶该壁纸吗?'
			let top =  e.currentTarget.dataset.topping;
			if(top == 0){
				content = '确定取消置顶该壁纸吗?';
			}
			that.setData({
				toppingVal : top
			})
			uni.showModal({
				title: '提示',
				content: content,
				cancelText: "取消", // 取消按钮的文字  
				confirmText: "确定", // 确认按钮文字  
				showCancel: true, // 是否显示取消按钮，默认为 true
				success: (res) => {
					if(res.confirm) {  
						that.toppingData();
					} 
				} 
			})
		},
		toppingData:function(){
			let that = this;
			var params = {
			  url: "/u/my/topping/"+that.id,
			  method: "GET",
			  data: {
				  topping:that.toppingVal
			  },
			  callBack: function (res) {
			    if(res.code == 200){
					uni.showToast({
						title:'操作成功',
						icon:'none'
					})
					that.setData({
						isTop :that.toppingVal
					})
					let pages = getCurrentPages(); // 获取所有页面栈实例列表
					let beforePage = pages[pages.length - 2]; // 上一页
					beforePage.$vm.loadPostLast(true);
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			  }
			};
			http.request(params); 
		},
		/**
		 * 跳转返回
		 */
		jumpBtn: function (options) {
			uni.navigateBack({
		      success: function() {
				  
		      }
		  });
		},
	}
};
</script>
<style>
@import "./detail.css"


</style>
